package com.hp.attendance.serlvet.history.OutGoing;

import com.hp.attendance.entity.Department;
import com.hp.attendance.entity.History;
import com.hp.attendance.entity.Position;
import com.hp.attendance.service.HistoryBysService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/updPreHistory")
public class HistoryPreUpdServlet extends HttpServlet {
    private HistoryBysService historyBysService = new HistoryBysService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            //---------------------------------------回显离职员工数据------------------------------------
            String employee_number = req.getParameter("employee_number");
            History history = historyBysService.getHistoryByNum(Integer.parseInt(employee_number));
            req.setAttribute("history",history);


            //回显部门名称
            Integer department_number1 = history.getDepartment_number();

            Integer department_number = history.getDepartment_number();
            Department department = historyBysService.getDepName(department_number);
            req.setAttribute("department",department);


            //回显职位名称
            Integer position_number = history.getPosition_number();
            Position position = historyBysService.getPosName(position_number);
            req.setAttribute("position",position);

            //跳转
            req.getRequestDispatcher("/pages/history_update.jsp").forward(req,resp);
        }



        catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

}
